<?php

namespace app\api\model;
use think\Model;
use think\Db;

class Admin extends Model{

    protected function initialize()
    {
        //需要调用`Model`的`initialize`方法
        parent::initialize();
        //TODO:自定义的初始化
    }

    // 自动转换
    protected function getCtimeAttr($vlue){
        return date("Y-m-d H:i:s",$vlue);
    }
    protected function getUtimeAttr($vlue){
        return date("Y-m-d H:i:s",$vlue);
    }
    /**
    * Notes: 查找管理员信息
    * Create Date: 2018/10/2
    * Create Time: 15:34
    * Create by :lijie
    * $w : 条件
    */
    public function findAdmin($w){

        $result = $this->where($w)->find();
        return $result;
    }

    /**
     * Notes: 修改管理员信息
     * Create Date: 2018/10/2
     * Create Time: 15:34
     * Create by :lijie
     * $w : 条件
     */
    public function editAdmin($w,$save){

        $result = $this->isUpdate(true)->allowField(true)->save($save,$w);
        return $result;
    }
    /**
     * Notes: 添加管理员
     * Create Date: 2018/10/2
     * Create Time: 15:34
     * Create by :lijie
     * $w : 条件
     */
    public function addAdmin($save){
        $result = $this->isUpdate(false)->allowField(true)->save($save);
        return $result;
    }

    /**
     * Notes: 查询管理员
     * Create Date: 2018/10/2
     * Create Time: 15:34
     * Create by :lijie
     * $w : 条件
     */
    public function selectAdmin($w,$page,$pageNum){
        $result = $this->where($w)
                       ->order("ctime desc")
                       ->page($page,$pageNum)
                       ->select();
        return $result;
    }

}